﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;

namespace Micro.Core.FrameWork.Config
{
    public abstract class BaseAppConfig
    {
        private readonly IConfiguration _configuration;

        protected BaseAppConfig(IConfiguration configuration)
        {
            _configuration = configuration;
            OssInfOssConfig = new OssConfig(configuration);
        }
        /// <summary>
        /// 数据库连接
        /// </summary>
        public string DbConnectString => _configuration["DbConnectString"];
        /// <summary>
        /// 数据库版本
        /// </summary>
        public string DbConnectVersion => _configuration["DbConnectVersion"];
        /// <summary>
        /// 阿里云key
        /// </summary>
        public string AccessKeyId => _configuration["AccessKeyId"];
        /// <summary>
        /// 阿里云密钥
        /// </summary>
        public string AccessKeySecret => _configuration["AccessKeySecret"];
        /// <summary>
        /// OSS存储
        /// </summary>
        public OssConfig OssInfOssConfig { get; set; }
        /// <summary>
        /// Redis配置
        /// </summary>
        public RedisConfig RedisConfig { get; set; }



    }
    /// <summary>
    /// 阿里云文件存储OSS
    /// </summary>
    public class OssConfig
    {
        private readonly IConfiguration _configuration;
        public OssConfig(IConfiguration configuration) => _configuration = configuration;
        /// <summary>
        /// 终结点
        /// </summary>
        public string EndPoint => _configuration.GetSection("OSSInfo")["EndPoint"];
        /// <summary>
        /// Buck
        /// </summary>
        public string BucketName => _configuration.GetSection("OSSInfo")["BucketName"];
    }

    public class RedisConfig
    {
        private readonly IConfiguration _configuration;
        public RedisConfig(IConfiguration configuration) => _configuration = configuration;
        /// <summary>
        /// Redis连接
        /// </summary>
        public string RedisConnectString => _configuration.GetSection("RedisConfig")["RedisConnectString"];
        /// <summary>
        /// Redis数据过期时间
        /// </summary>
        public string DefaultTimeExpire => _configuration.GetSection("RedisConfig")["DefaultTimeExpire"];
    }
}
